﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;
using System.Diagnostics;

namespace WebPALTT.Lib
{
    public partial class RunMonitor : Form
    {
        public delegate void ThreadStarted();
        public delegate void ThreadFinished();
        public delegate void ScenarioStarted();
        public delegate void ScenarioFinished();
        public delegate void TestFinished();
        public delegate void TestCancelled();

        public ThreadStarted threadStartedDelegate;
        public ThreadFinished threadFinishedDelegate;
        public ScenarioStarted scenarioStartedDelegate;
        public ScenarioFinished scenarioFinishedDelegate;
        public TestFinished testFinishedDelegate;
        public TestCancelled testCancelledDelegate;

        //TestDefinition testdef;
        Stopwatch timer = new Stopwatch();
        //ThreadWorker worker;
        public RunMonitor()
        {
            InitializeComponent();

            threadStartedDelegate = new ThreadStarted(ThreadStartedMethod);
            threadFinishedDelegate = new ThreadFinished(ThreadFinishedMethod);
            scenarioStartedDelegate = new ScenarioStarted(ScenarioStartedMethod);
            scenarioFinishedDelegate = new ScenarioFinished(ScenarioFinishedMethod);
            testFinishedDelegate = new TestFinished(TestFinishedMethod);
            testCancelledDelegate = new TestCancelled(TestCancelledMethod);
        }

        public void StartTest()
        {
            //this.ShowDialog();
        }

        int scenariosRunning = 0;
        int scenariosFinished = 0;
        int threadsRunning = 0;
        int threadsFinished = 0;

        public void ThreadStartedMethod() 
        {
            threadsRunning++;
            lbl_ThreadRunning.Text = "" + threadsRunning;
        }
        public void ThreadFinishedMethod() 
        {
            threadsRunning--;
            threadsFinished++;
            lbl_ThreadRunning.Text = "" + threadsRunning;
            lbl_ThreadFinished.Text = "" + threadsFinished;
        }
        public void ScenarioStartedMethod() 
        {
            scenariosRunning++;
            lbl_SceneRunning.Text = "" + scenariosRunning;
        }
        public void ScenarioFinishedMethod() 
        {
            scenariosRunning--;
            scenariosFinished++;
            lbl_SceneRunning.Text = "" + scenariosRunning;
            lbl_SceneFinished.Text = "" + scenariosFinished;
        }
        public void TestFinishedMethod() 
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        public void TestCancelledMethod() { }
    }
}
